<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>作业2</title>
    <style>  
      .error {  
          color: red;  
          font-style: italic;  
      }  
  </style>  
</head>
<body>
              <form id="myform">
                <label for="username">用户名：</label><br>  
              <input type="text" id="username" name="username"><span id="cu"></span><br>  
              <label for="email">电子邮件：</label><br>  
              <input type="text" id="email" name="email"><span id="ce"></span><br> 
              <button type="button" onclick="myFunction()" >检测</button>
              </form>
              
        
        <script>
            function myFunction(){
            var username = document.getElementById("username").value;  
            var email = document.getElementById("email").value;  
            var cu = document.getElementById("cu");  
            var ce = document.getElementById("ce");  
  
            if (username.length < 8) {  
                cu.innerHTML = username;  
                document.getElementById("username").value =null;  
                cu.className = "error";  
            } else {  
                cu.className = "";  
            }  
  
            if (email.indexOf("@") == -1 || email.split("@").length > 1) {  
                ce.innerHTML = username;  
                document.getElementById("email").value =null;  
                ce.className = "error";  
            } else {  
                ce.className = "";  
            }  
            }
        </script>
        <script>
        function showDate(){
	    var d = new Date();
       document.getElementById("divDate").innerHTML=d.toLocaleString();
	   setTimeout("showDate()",1000);}
        </script>
        <body onload="showDate()">
		<div id="divDate" style="color:red;font-size:30px;">
</body>
</html>